using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PearlyGates;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Graphics;

namespace PearlyGates
{
    class Final : GameScreen
    {
        Texture2D background;
        Song backgroundSong;
        int delay = 0;
        int screenNum = 0;

        public override void LoadContent()
        {
            backgroundSong = ScreenManager.Game.Content.Load<Song>("success");

            MediaPlayer.IsRepeating = false;
            MediaPlayer.Volume = 1.0f;
            MediaPlayer.Play(backgroundSong);

            base.LoadContent();
        }

        public override void HandleInput(InputState input)
        {
            PlayerIndex playerIndex;
            if (input.IsMenuCancel(null, out playerIndex))
            {
                MediaPlayer.Stop();
                ScreenManager.AddScreen(new Menu(), null);
                ExitScreen();
            }
            base.HandleInput(input);
        }

        public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
        {
            if (delay == 0)
            {
                if (screenNum == 24)
                    screenNum = 22;

                string fileName = "endbackground_" + (++screenNum).ToString();
                background = ScreenManager.Game.Content.Load<Texture2D>(fileName);
                delay = 5;
            }
            else
            {
                delay--;
            }

            base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);
        }

        public override void Draw(GameTime gameTime)
        {
            if (background != null)
            {
                ScreenManager.SpriteBatch.Begin();
                ScreenManager.SpriteBatch.Draw(background, Vector2.Zero, Color.White);
                ScreenManager.SpriteBatch.End();
            }

            base.Draw(gameTime);
        }
    }
}
